package com.easyfun.healthmagicbox.comm.json;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.DoctorAndSuggestion;

public class DoctorAndSuggestionJsonWrapper<T extends JsonWrapper> extends
		AbstractJsonWrapper<T,DoctorAndSuggestion> {
	
	public DoctorAndSuggestionJsonWrapper()
	{
		super();
	}
	public DoctorAndSuggestionJsonWrapper(DoctorAndSuggestion ds)
	{
		super(ds);
	}
	
	public void deserializeFromObj(JSONObject obj) throws JSONException {
		if (mpp == null) {
			mpp = new DoctorAndSuggestion();
		}
		mpp.setDoctorID(obj.getString("doctorID"));
		mpp.setSuggestion(obj.getString("suggestion"));
		mpp.setPersonID(obj.getString("personID"));
		mpp.setSuggestionTime(obj.getString("created"));
		mpp.setSuggestionsyncid(Integer.valueOf(obj.getString("id")));
	}

	public JSONObject serializeToObj() throws JSONException {
		JSONObject serializedObj = new JSONObject();
		serializedObj.put("doctorID", mpp.getDoctorID());
		serializedObj.put("suggestion", mpp.getSuggestion());
		serializedObj.put("personID", mpp.getPersonID());
		serializedObj.put("suggestionTime", mpp.getSuggestionTime().toString());
		serializedObj.put("suggestionsyncid", mpp.getSuggestionsyncid()
				.toString());

		return serializedObj;
	}

}
